const Promise = require('./es6-promise.min.js')


module.exports = {
    login: function() {
        return new Promise((resolve, reject) => {
            wx.login({ success: resolve, fail: reject })
        })
    },

    getUserInfo: function() {
        return new Promise((resolve, reject) => {
            wx.getUserInfo({ success: resolve, fail: reject })
        })
    },

    setStorage: function(key, value) {
        return new Promise((resolve, reject) => {
            wx.setStorage({ key: key, data: value, success: resolve, fail: reject })
        })
    },

    getStorage: function(key) {
        return new Promise((resolve, reject) => {
            wx.getStorage({ key: key, success: resolve, fail: reject })
        })
    },

    getLocation: function(type) {
        return new Promise((resolve, reject) => {
            wx.getLocation({ type: type, success: resolve, fail: reject })
        })
    },

    successToast: function(msg = '提示', duration = 2000) {
        wx.showToast({
            title: msg,
            icon: "success",
            duration: duration
        })
    },

    // failToast: function(msg = '请稍等', duration = 2000) {
    //     wx.showToast({
    //         title: msg,
    //         icon: "warn",
    //         duration: duration
    //     })
    // },
    
    loadingToast: function() {
        wx.showToast({
          title: '加载中',
          icon: 'loading',
          duration: 10000
        })
    },
}
